Skip to content

[GH-3545] Store ISO WKB in GeoParquet files - #3558

Merged
jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:fix/geoparquet-iso-wkb
Nov 18, 2026
Merged

jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:fix/geoparquet-iso-wkb

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

The GeoParquet writer stored a geometry with a Z coordinate as EWKB: the type word of POINT Z (1 2 3) was 0x80000001. The GeoParquet specification asks for the WKB of the OGC and ISO standards, where the type code of that point is 1001.

The writer now rewrites the type words of each geometry with PublicWkbHeaderAdapter.toIsoWkbInPlace and leaves the coordinates as they are. This new method changes the type words in the array the WKB writer returned, so the conversion allocates no second array. The existing toIsoWkb, which returns a copy, is unchanged for its other callers. This applies to every geometry the geoparquet format writes, on all supported Spark versions: root geometry columns, the members of collections, and geometries nested in other columns.

What stays the same:

  • Geometries without a Z coordinate. The two encodings are the same for XY, and the adapter returns the bytes it was given.
  • The layout of the members of a geometry collection. A collection with both XY and XYZ members is stored with the type codes of both, for example 1007, 2 and 1001, where it had 0x80000007, 2 and 0x80000001 before. ISO WKB asks for Z members throughout such a collection, and Spark's native geometry type rejects it. The documentation now states this limit.
  • The geo metadata. geometry_types was already derived from the declared layout and still is; it now reads the ISO type code.
  • Reading. Sedona reads both forms, so files written before this change stay readable.

How was this patch tested?

GeoParquetDimensionsSuite has two new tests that compare the stored bytes with hand-built ISO WKB: one for a point, a point with Z, a line with Z, a multipoint with Z and a geometry collection with Z members in a root column, and one for a geometry inside an array and inside a struct. The existing write test of that suite now also checks the type code of every geometry it writes. All of them fail without the change, because the stored type word carries the EWKB flag. A third new test pins the stored type codes of a collection with XY and XYZ members.

The new PublicWkbHeaderAdapterSuite covers toIsoWkbInPlace: it returns the array it was given with ISO type words, for a single geometry and for nested collections in both byte orders, leaves XY and ISO input untouched, returns a new array for WKB with an embedded SRID, and rejects invalid WKB without changing it.

The GeoParquet suites pass locally on Spark 4.1 / Scala 2.13, Spark 3.5 / Scala 2.12 and Spark 4.2 / Scala 2.13 (including the GeoParquet suites of the spark-4.2 module).

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

The GeoParquet writer marked a Z coordinate with the EWKB flag bit of the
type word. The GeoParquet specification asks for the WKB of the OGC and ISO
standards, which uses the type codes 1001 to 1007 instead. The writer now
converts the type words of every geometry it stores, including collection
members and geometries nested in other columns. Geometries without Z and
the geo metadata are unchanged.
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Nov 18, 2026
The GeoParquet writer converted each geometry with a Z coordinate to ISO
WKB through a second array of the same size. The WKB writer already returns
a new array without an SRID, so the type words are now rewritten in that
array by the new PublicWkbHeaderAdapter.toIsoWkbInPlace. toIsoWkb is
unchanged for its other callers.

A geometry collection keeps the coordinate layout of each member, so a
collection with XY and XYZ members is stored with the type codes of both.
The tutorials now say that Sedona writes the Z dimension with ISO type
codes and describe this limit, and a test pins the stored codes.
@jiayuasu
jiayuasu merged commit acb4ae0 into apache:master Nov 18, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeoParquet writer stores XYZ geometries with the EWKB Z flag instead of ISO WKB type codes

1 participant